package com.example.demo.leetcode.thread;


import java.util.concurrent.*;

/**
 * 异常处理
 */
public class CallableThread implements Callable<String> {


    @Override
    public String call() throws Exception {
        System.out.println("线程开始");
        exceptionMethod();
        System.out.println("线程结束");
        return "success";
    }

    public void exceptionMethod(){
        throw new RuntimeException("运行时异常");
    }

    public static void main(String[] args) {
        CallableThread thread = new CallableThread();
        CallableThread thread2 = new CallableThread();
        ThreadPoolExecutor pool = new ThreadPoolExecutor(10,10,10, TimeUnit.SECONDS,new ArrayBlockingQueue(1000));
        try{
            Future<String> f1 = pool.submit(thread);
            Future<String> f2 = pool.submit(thread2);
            f1.get();
            f2.get();
        }catch (Exception e){
            System.out.println(e.getMessage());
        }finally {
            pool.shutdown();
        }


    }


}
